package com.bwie.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.pojo.TbBrand;
import com.bwie.service.TbBrandService;
import com.bwie.mapper.TbBrandMapper;
import com.bwie.utils.R;
import com.bwie.vo.BrandVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author 31439
* @description 针对表【tb_brand(品牌表)】的数据库操作Service实现
* @createDate 2025-07-19 11:30:28
*/
@Service
public class TbBrandServiceImpl extends ServiceImpl<TbBrandMapper, TbBrand>
    implements TbBrandService{
    @Autowired
    TbBrandMapper tbBrandMapper;

    @Override
    public R getBrandList(BrandVo brandVo) {
        Page<TbBrand> page = new Page<>(brandVo.getPageNum(), brandVo.getPageSize());
        Page<TbBrand> brandPage = tbBrandMapper.getBrandList(page,brandVo);
        return R.OK(brandPage);
    }

    @Override
    public R changeBrandStatus(TbBrand tbBrand) {
        TbBrand brand = tbBrandMapper.selectById(tbBrand.getBrandId());
        if(brand == null){
            return R.ERROR(500,"品牌不存在");
        }
        brand.setBrandStatus(tbBrand.getBrandStatus());
        brand.setUpdateTime(new Date());
        tbBrandMapper.updateById(brand);
        return R.OK();
    }

    @Override
    public R AddBrand(TbBrand tbBrand) {
        tbBrand.setCreateTime(new Date());
        tbBrandMapper.insert(tbBrand);
        return R.OK();
    }
}




